package com.code.module.funds.service;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.code.base.acc.pojo.AccPsn;
import com.code.base.acc.service.AccPsnService;
import com.code.base.busi.pojo.BusiDepList;
import com.code.base.busi.pojo.BusiDepReq;
import com.code.base.busi.service.BusiDepListService;
import com.code.base.busi.service.BusiDepReqService;
import com.code.base.sys.pojo.SysUser;


@Service
public class FundsService {
	
	@Resource
	private AccPsnService accPsnService;
	
	@Resource
	private BusiDepListService busiDepListService;
	
	@Resource
	private BusiDepReqService busiDepReqService;

	public void fundsDep(AccPsn accPsn, Double payMoney, String payDate, SysUser sysUser) {
		accPsn.setState("1");
		accPsnService.updateData(accPsn);
		
		BusiDepList busiDepList = new BusiDepList();
		busiDepList.setBldId(accPsn.getBldId());
		busiDepList.setDepType("01");
		busiDepList.setDepYear("0000");
		busiDepList.setOrderNo(0);
		busiDepList.setRecDate(new Date());
		busiDepList.setRecOper(sysUser.getUserName());
		busiDepList.setState("4");
		busiDepList.setDueArea(accPsn.getFPayArea());
		busiDepList.setDueAmount(accPsn.getFPayDue());
		busiDepList.setPayAmount(payMoney);
		busiDepList.setDepDate(payDate);
		busiDepList.setPsnAccNo(String.valueOf(accPsn.getId()));
		
		busiDepListService.insertData(busiDepList);
	}
	
	public void fundsReq(BusiDepList[] busiDepLists, String bank, String reqDate, String validDate) {
		BusiDepList temp = null;
		String accPsnIds = "";
		for (BusiDepList busiDepList : busiDepLists) {
			busiDepList.setOrderNo(1);
			busiDepList.setState("3");
			busiDepListService.updateData(busiDepList);
			
			accPsnIds += busiDepList.getPsnAccNo() + ",";
			temp = busiDepList;
		}
		
		accPsnIds = accPsnIds.substring(0, accPsnIds.length() - 1);
		
		BusiDepReq busiDepReq = new BusiDepReq();
		busiDepReq.setBankCode(bank);
		busiDepReq.setCertDate(reqDate);
		busiDepReq.setValidDate(validDate);
		
		busiDepReqService.insertData(busiDepReq);
	}
	
}
